package seeders

import (
	"hyper/app/Models"
	"hyper/supports/database"
)

// 添加菜单权限表
func PowerSeeder() {
	str := []uint{1, 2, 3, 4}
	if !isPowerExist() {
		for _, v := range getMenuList() {
			for _, i := range str {
				_power := []Models.Power{
					{
						MenuId: v.ID,
						Name:   v.Name,
						Type:   i,
						WebId:  v.WebId,
					},
				}
				database.DB.Create(&_power)
			}
		}
	}
}

// 查找数据
func isPowerExist() bool {
	var count int64
	database.DB.Model(&Models.Power{}).Count(&count)
	return count > 0
}

// 查找菜单数据
func getMenuList() (menus []Models.Menu) {
	database.DB.Model(&Models.Menu{}).Find(&menus)
	return
}
